package com.ebt.m.widget.image_chooser;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;

import java.util.ArrayList;


/**
 * @author Damon.Han
 * @Description: 图片预览act
 * @date 2016年1月7日 下午5:00:40
 */
public class ImageChooserPreview extends FragmentActivity {
    public static final int requestCode = 9999;
    public static final String EXTRA_IMAGE_INDEX = "image_index";
    public static final String EXTRA_IMAGE_URLS = "image_urls";
    private HackyViewPager mPager;
    private int pagerPosition;
    private Context context;
    TextView indicator;
    private ImageView mImageCheck;
    private String dateStr = "";
    private ArrayList<String> urls;
    private ImagePagerAdapter mImagePagerAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        context = this;
        setContentView(R.layout.img_chooser_preview);
        indicator = (TextView) findViewById(R.id.indicator);
        mImageCheck = (ImageView)findViewById(R.id.mImageCheck);
        pagerPosition = getIntent().getIntExtra(EXTRA_IMAGE_INDEX, 0);
        urls = (ArrayList<String>) getIntent().getSerializableExtra("data");

        mPager = (HackyViewPager) findViewById(R.id.pager);
        mPager.setOnPageChangeListener(new OnPageChangeListener() {

            @Override
            public void onPageScrollStateChanged(int state) {
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                indicator.setText((position + 1) + "/" + urls.size());
            }

        });
        if (urls == null) {
            urls = new ArrayList<>();
        }
        initData();
        indicator.setText((pagerPosition + 1) + "/" + urls.size());
    }

    private void initData() {
        mImagePagerAdapter = new ImagePagerAdapter(getSupportFragmentManager(), urls);
        mPager.setAdapter(mImagePagerAdapter);
        mPager.setCurrentItem(pagerPosition, true);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.fade_in_center, R.anim.fade_out_center);
    }
}
